#!/bin/bash

FILES=("movies.list" "aka-names.list" "aka-titles.list" "genres.list" )
COMMENTS=( 16 16 18 377 )

f=0
while [ $f -lt ${#FILES[@]} ]; do
    file="${FILES[$f]}.tmp"
    comm=${COMMENTS[$f]}
    endl=`tail --lines=+$comm $file | grep -n "\---------" | awk -F : '{print $1}'`
    if [ ! -z $endl ]; then
	tail --lines=+$comm "$file" | head --lines=$[endl-1] > "${file/.tmp/.tmp2}"
    else
	tail --lines=+$comm "$file" > "${file/.tmp/.tmp2}"
    fi
    f=$[f+1]

    mv "${file/.tmp/.tmp2}" "$file"
done
